module.exports = (sequelize, DataTypes) => {
    return sequelize.define(
        "publish_comment",
        {
            comment_id: {
                type: DataTypes.INTEGER,
                primaryKey: true,
                autoIncrement: true,
            },
            // 新增：关联发布表的ID
            publish_id: {
                type: DataTypes.INTEGER,
                allowNull: false,
                references: {
                    model: "publish",
                    key: "publish_id"
                }
            },
            // 新增：关联用户表的ID
            user_id: {
                type: DataTypes.INTEGER,
                allowNull: false,
                references: {
                    model: "user",
                    key: "id"
                }
            },
            content: {
                type: DataTypes.TEXT,
                allowNull: false, // 评论内容不能为空
            },
            // 新增：支持评论回复（父评论ID，null表示一级评论）
            parent_id: {
                type: DataTypes.INTEGER,
                allowNull: true,
                defaultValue: null,
                references: {
                    model: "publish_comment",
                    key: "comment_id"
                }
            },
            is_deleted: {
                type: DataTypes.BOOLEAN,
                allowNull: false,
                defaultValue: false // 默认未删除
            },
        },
        {
            tableName: "publish_comment",
            timestamps: true,
        }
    );
};